
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:qianyi/state/token.dart';

import '../../entity/home/video_list_entity.dart';
import '../../entity/profile/own_video_list_entity.dart';
import '../../entity/recommend/VideoCircleEntity.dart';
import '../../entity/search/search_data_entiy.dart';
import '../../network/base_entity.dart';
import '../../network/http_config.dart';
import '../../network/http_entity.dart';
import '../../network/http_manager.dart';
import '../../other/user_manager.dart';
import '../../ui/widget/custom_refresh_mixin.dart';

class SearchViewModel extends ChangeNotifier  with CustomRefreshMixin {
  TokenController tokenController = Get.find();
  TabController? tabController;
  int currentIndex = 0;
  List<String>? allSearchRecord;

  @override
  Future<List> requestList(int page) async {
    List tempL = [];
    Map<String, dynamic> params = {};
    params["pageSize"] = 10;
    params["pageNum"] = page;
    // String id = UserManager.userEntity!.userInfo!.id!;
    if(tokenController.uid.length <= 0) {
      return tempL;
    }
    params["uid"] =  tokenController.uid;;
    HttpEntity? result1 = await HttpManager.getInstance().request(url: "/platform/searchRecord/getAllSearchRecord?",params: params, method: Method.get) as HttpEntity;
    if (result1?.isSuccess() == true) {
      List<dynamic> list = result1.getOriData()["data"];
      allSearchRecord = list.cast<String>();

    } else {
    }
    HttpEntity? result = await HttpManager.getInstance().request(url: "/search/searchRecord/esSearchRecord", method: Method.get) as HttpEntity;
    if (result?.isSuccess() == true) {
      SearchItemList listResult = SearchItemList.fromJson(result.getOriData()["data"]);
      List<SearchItem>? temps = listResult.items;
      if (temps != null) {
        tempL.addAll(temps);
      }

    } else {
    }
    notifyListeners();
    return tempL;
  }


  @override
  void onRequestComplete() {
    notifyListeners();
  }

  @override
  Future<List> requestListByParam(int page, Map<String, dynamic> param) {
    // TODO: implement requestListByParam
    throw UnimplementedError();
  }
}